{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Python Exercise -Version Notebook"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- This is the exercise based on the forked repository on GitHub\n",
    "-  Help to improve it if you want, just add the solution under the question\n",
    "- Each notebook only contains 10 questions which is convenient for everyone to locate each question to modify, you can add your own name under the author's list below, let's contribute together !\n",
    "- To visit my personal site: [Click Here](http://yaozeliang.com/resume)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 1\n",
    "\n",
    "\n",
    "Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5,\n",
    "between 2000 and 3200 (both included).\n",
    "The numbers obtained should be printed in a comma-separated sequence on a single line.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2002, 2009, 2016, 2023, 2037, 2044, 2051, 2058, 2072, 2079, 2086, 2093, 2107, 2114, 2121, 2128, 2142, 2149, 2156, 2163, 2177, 2184, 2191, 2198, 2212, 2219, 2226, 2233, 2247, 2254, 2261, 2268, 2282, 2289, 2296, 2303, 2317, 2324, 2331, 2338, 2352, 2359, 2366, 2373, 2387, 2394, 2401, 2408, 2422, 2429, 2436, 2443, 2457, 2464, 2471, 2478, 2492, 2499, 2506, 2513, 2527, 2534, 2541, 2548, 2562, 2569, 2576, 2583, 2597, 2604, 2611, 2618, 2632, 2639, 2646, 2653, 2667, 2674, 2681, 2688, 2702, 2709, 2716, 2723, 2737, 2744, 2751, 2758, 2772, 2779, 2786, 2793, 2807, 2814, 2821, 2828, 2842, 2849, 2856, 2863, 2877, 2884, 2891, 2898, 2912, 2919, 2926, 2933, 2947, 2954, 2961, 2968, 2982, 2989, 2996, 3003, 3017, 3024, 3031, 3038, 3052, 3059, 3066, 3073, 3087, 3094, 3101, 3108, 3122, 3129, 3136, 3143, 3157, 3164, 3171, 3178, 3192, 3199]\n"
     ]
    }
   ],
   "source": [
    "result=[]\n",
    "for i in range(2000,3201):\n",
    "    if i%7==0 and i%5 != 0:\n",
    "        result.append(i)\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 2\n",
    "\n",
    "Write a program which can compute the factorial of a given numbers.\n",
    "The results should be printed in a comma-separated sequence on a single line.\n",
    "Suppose the following input is supplied to the program:\n",
    "8\n",
    "Then, the output should be:\n",
    "40320\n",
    "\n",
    "Hints:\n",
    "In case of input data being supplied to the question, it should be assumed to be a console input."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> Solution 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "40320\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "print(np.math.factorial(8))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> Solution 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 3\n",
    "\n",
    "With a given integral number n, write a program to generate a dictionary that contains (i, i*i) such that is an integral number between 1 and n (both included). and then the program should print the dictionary.\n",
    "Suppose the following input is supplied to the program:\n",
    "8\n",
    "Then, the output should be:\n",
    "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}\n",
    "\n",
    "Hints:\n",
    "In case of input data being supplied to the question, it should be assumed to be a console input.\n",
    "Consider use dict()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> Solution 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}\n"
     ]
    }
   ],
   "source": [
    "n=int(input(\"n:\"))\n",
    "res={}\n",
    "for i in range(1,n+1):\n",
    "    res[i]=i**2\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> Solution 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 4\n",
    "\n",
    "Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple which contains every number.\n",
    "Suppose the following input is supplied to the program:\n",
    "34,67,55,33,12,98\n",
    "Then, the output should be:\n",
    "['34', '67', '55', '33', '12', '98']\n",
    "('34', '67', '55', '33', '12', '98')\n",
    "\n",
    "Hints:\n",
    "In case of input data being supplied to the question, it should be assumed to be a console input.\n",
    "tuple() method can convert list to tuple"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['34', '67', '55', '33', '12', '98'] ('34', '67', '55', '33', '12', '98')\n"
     ]
    }
   ],
   "source": [
    "value=input().split(\",\")\n",
    "print(value,tuple(value))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 5\n",
    "\n",
    "\n",
    "Define a class which has at least two methods:\n",
    "getString: to get a string from console input\n",
    "printString: to print the string in upper case.\n",
    "Also please include simple test function to test the class methods.\n",
    "\n",
    "Hints:\n",
    "Use __init__ method to construct some parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "class InputoutputString():\n",
    "    def init(self):\n",
    "        pass\n",
    "    def getString(self):\n",
    "        self.s=input()\n",
    "    def printString(self):\n",
    "        print(self.s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "string\n"
     ]
    }
   ],
   "source": [
    "s=InputoutputString()\n",
    "s.getString()\n",
    "s.printString()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 6\n",
    "\n",
    "\n",
    "Write a program that calculates and prints the value according to the given formula:\n",
    "Q = Square root of [(2 * C * D)/H]\n",
    "Following are the fixed values of C and H:\n",
    "C is 50. H is 30.\n",
    "D is the variable whose values should be input to your program in a comma-separated sequence.\n",
    "Example\n",
    "Let us assume the following comma separated input sequence is given to the program:\n",
    "100,150,180\n",
    "The output of the program should be:\n",
    "18,22,24\n",
    "\n",
    "Hints:\n",
    "If the output received is in decimal form, it should be rounded off to its nearest value (for example, if the output received is 26.0, it should be printed as 26)\n",
    "In case of input data being supplied to the question, it should be assumed to be a console input."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18\n",
      "22\n",
      "24\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "C=50\n",
    "H=30\n",
    "items=[int(x) for x in input().split(\",\")]\n",
    "for D in items:\n",
    "    Q=int(np.math.sqrt(2*C*D/H))\n",
    "    print(Q)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 7\n",
    "\n",
    "Write a program which takes 2 digits, X,Y as input and generates a 2-dimensional array. The element value in the i-th row and j-th column of the array should be i*j.\n",
    "Note: i=0,1.., X-1; j=0,1,¡­Y-1.\n",
    "Example\n",
    "Suppose the following inputs are given to the program:\n",
    "3,5\n",
    "Then, the output of the program should be:\n",
    "[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]] \n",
    "\n",
    "Hints:\n",
    "Note: In case of input data being supplied to the question, it should be assumed to be a console input in a comma-separated form."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0. 0. 0. 0. 0.]\n",
      " [0. 1. 2. 3. 4.]\n",
      " [0. 2. 4. 6. 8.]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "dim=[int(x) for x in input().split(\",\")]\n",
    "output=np.zeros((3,5))\n",
    "for x in range(dim[0]):\n",
    "    for y in range(dim[1]):\n",
    "        output[x][y]=x*y\n",
    "print(output)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 8\n",
    "\n",
    "Write a program that accepts a comma separated sequence of words as input and prints the words in a comma-separated sequence after sorting them alphabetically.Suppose the following input is supplied to the program:\n",
    "without,hello,bag,world\n",
    "\n",
    "Then, the output should be:\n",
    "bag,hello,without,world"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bag,hello,without,world\n"
     ]
    }
   ],
   "source": [
    "value=[x for x in input().split(\",\")]\n",
    "value.sort()\n",
    "s=\"\"\n",
    "for i in value:\n",
    "    s=s+i\n",
    "    if i!=value[-1]:\n",
    "        s=s+\",\"\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 9\n",
    "\n",
    "Write a program that accepts sequence of lines as input and prints the lines after making all characters in the sentence capitalized.\n",
    "Suppose the following input is supplied to the program:\n",
    "\n",
    "```\n",
    "Hello world\n",
    "Practice makes perfect\n",
    "```\n",
    "Then, the output should be:\n",
    "```\n",
    "HELLO WORLD\n",
    "PRACTICE MAKES PERFECT\n",
    "```\n",
    "Hints:\n",
    "In case of input data being supplied to the question, it should be assumed to be a console input."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "HELLO\n"
     ]
    }
   ],
   "source": [
    "value=input()\n",
    "res=\"\"\n",
    "for chr in value:\n",
    "    if chr.islower():\n",
    "        res=res+chr.upper()\n",
    "    else:\n",
    "        res=res+chr\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 10\n",
    "\n",
    "Write a program that accepts a sequence of whitespace separated words as input and prints the words after removing all duplicate words and sorting them alphanumerically.\n",
    "Suppose the following input is supplied to the program:\n",
    "```\n",
    "hello world and practice makes perfect and hello world again\n",
    "```\n",
    "Then, the output should be:\n",
    "```\n",
    "again and hello makes perfect practice world\n",
    "```\n",
    "Hints:\n",
    "In case of input data being supplied to the question, it should be assumed to be a console input.\n",
    "We use set container to remove duplicated data automatically and then use sorted() to sort the data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['again', 'and', 'hello', 'makes', 'perfect', 'practice', 'world']\n"
     ]
    }
   ],
   "source": [
    "value=input().split(\" \")\n",
    "value=list(set(value))\n",
    "value.sort()\n",
    "print(value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.6rc1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
